/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-05-25 17:25:04
 * @LastEditTime: 2024-09-14 18:35:53
 * @FilePath: /nest_study/server/src/modules/system/role/role.controller.ts
 */
import { Controller, Get, Post, Body, Delete, Put, Query, Request } from '@nestjs/common';
import { RoleService } from './role.service';
import { CreateRoleDto, DeleteRolerDto, findRoleDto, ListRoleDto, UpdateRoleDto } from './dto/index.dto';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';

@ApiTags('角色管理')
@ApiBearerAuth()
@Controller('system/role')
export class RoleController {
  constructor(private readonly roleService: RoleService) { }

  @ApiOperation({
    summary: '角色-创建'
  })
  @ApiBody({
    type: CreateRoleDto,
    required: true
  })
  @Post("/create")
  create(@Body() createRoleDto: CreateRoleDto,@Request() req) {
    return this.roleService.create(createRoleDto);
  }

  @ApiOperation({
    summary: '角色-列表'
  })
  @Get("/list")
  list(@Query() query: ListRoleDto,) {
    return this.roleService.query(query);
  }

  @ApiOperation({
    summary: '角色-权限'
  })
  @Get("/auth")
  auth(@Request() req) {
    const user = req.user.user;
    return this.roleService.findAuth(user);
  }

  @ApiOperation({
    summary: '角色-详情'
  })
  @ApiBody({
    type: findRoleDto,
    required: true
  })
  @Get('/info')
  findOne(@Query() query: findRoleDto) {
    return this.roleService.findOne(query);
  }

  @ApiOperation({
    summary: '角色-更新'
  })
  @ApiBody({
    type: UpdateRoleDto,
    required: true
  })
  @Put('/update')
  update(@Body() updateRoleDto: UpdateRoleDto) {
    return this.roleService.update(updateRoleDto);
  }

  @ApiOperation({
    summary: '角色-删除'
  })
  @ApiBody({
    type: DeleteRolerDto,
    required: true
  })
  @Delete('/delete')
  remove(@Body() roleInfo: DeleteRolerDto) {
    return this.roleService.remove(roleInfo);
  }
}

